package com.glorysoft.lipuxinpda.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.glorysoft.lipuxinpda.R;
import com.glorysoft.lipuxinpda.entity.MessageInfoEntity;
import com.glorysoft.lipuxinpda.entity.RealTimeMessageReturnEntity;

import java.util.List;

public class RealTimeRecyclerViewAdapter extends RecyclerView.Adapter<RealTimeRecyclerViewAdapter.ViewHolder>{

    private List<MessageInfoEntity> mList;

    public void setmList(List<MessageInfoEntity> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_realtime_message, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        MessageInfoEntity entity = mList.get(position);
        holder.tv_operand.setText(entity.getOPERAND());
        holder.tv_operation_content.setText(entity.getOPERATION_CONTENT());
        holder.tv_msg_id.setText(entity.getMSG_ID());
        holder.tv_created_time.setText(entity.getCREATED_TIME());
    }

    @Override
    public int getItemCount() {
        return Math.max(mList.size(), 0);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_operand;//操作终端
        private TextView tv_operation_content;//操作内容
        private TextView tv_msg_id;//PDA MessageID
        private TextView tv_created_time;//时间

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_operand = itemView.findViewById(R.id.tv_operand);
            tv_operation_content = itemView.findViewById(R.id.tv_operation_content);
            tv_msg_id = itemView.findViewById(R.id.tv_msg_id);
            tv_created_time = itemView.findViewById(R.id.tv_created_time);
        }
    }
}
